/**
 * 创建 Marker 图标标记
 * @param AMap AMap 实例
 * @param position 经纬度
 * @param width 宽度
 * @param height 高度
 * @param iconUrl 图片地址
 * @returns {Marker} 图标
 */
export const createMarker = (
  AMap: any,
  position: [number, number],
  width: number,
  height: number,
  iconUrl: string
) => {
  const size = new AMap.Size(width, height);
  const offset = new AMap.Pixel(0, 0);
  const [long, lat] = position;

  // 创建一个 Icon
  const icon = new AMap.Icon({
    // 图标尺寸
    size: size,
    // 图标的取图地址
    image: iconUrl,
    // 图标所用图片大小
    imageSize: size,
    // 图标取图偏移量
    imageOffset: offset,
  });

  // 将 icon 传入 marker
  const marker = new AMap.Marker({
    position: new AMap.LngLat(long, lat),
    icon: icon,
    offset: offset,
  });
  return marker;
};

/**
 * 创建导航路径
 * @param AMap AMap实例
 * @param path 路径列表
 * @param color 路径颜色
 * @param strokeWeight 路径线宽
 * @param strokeStyle 路径类型
 * @returns {Polyline} 路径
 */
export const createPloyLine = (
  AMap: any,
  path: Array<[number, number]>,
  color: string,
  strokeWeight: number = 33,
  strokeStyle: "solid" | "dashed" = "solid"
) => {
  const polyline = new AMap.Polyline({
    path, //设置线覆盖物路径
    strokeColor: color, //线颜色
    strokeWeight, //线宽
    strokeStyle, //线样式
  });
  return polyline;
};
